package model.bullet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

import model.cell.tower.AbstractTower;
import model.enemy.AbstractEnemy;



public class RocketBullet extends AbstractBullet {

	
	public RocketBullet(Point pos, AbstractEnemy enemy, AbstractTower tower) {
		
		super(pos, enemy, tower);
		_damage = 5;
	}
	
	
	public void draw(Graphics g) {
		
		Color c = g.getColor();
		g.setColor(color);
		g.fillOval((int)_posX - 2, (int)_posY -2, 5, 5);
		g.setColor(c);
	}
	
	
	public synchronized void move() {
		
		if (_enemy == null || _enemy.getHealth() == 0) { 
			_findNewTarget();
			return;
		}
		Point enemyPos = _enemy.getPosition();
		
		float distanceX = enemyPos.x - _posX;
		float distanceY = enemyPos.y - _posY;
		float distanceSum = Math.abs(distanceX) + Math.abs(distanceY);
		
		if (distanceSum < 1) {
			_hitEnemy();
			_destroy();
			return;
		}
		
		float speedX = (distanceX * _speedCoef) / distanceSum;
		float speedY = (distanceY * _speedCoef) / distanceSum;
		
		_posX += speedX;
		_posY += speedY;
	}
	
}
